package gsw.demo.mvvm;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import gsw.demo.mvvm.databinding.ActivityMainBinding;


public class MainActivity extends AppCompatActivity {
    User user = null;
    Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        user = new User("jett", "123456", "https://img1.3lian.com/2015/w13/54/d/26.jpg");
        binding.setUser(user);
        updateUser();
    }

    /**
     * 修改User数据，UI自动更新
     */
    private void updateUser() {
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                user.setName("lance");
            }
        }, 3000);
    }

    /**
     * 打开列表
     */
    public void openList(View view) {
        Intent i = new Intent(this, ActivityList.class);
        startActivity(i);
    }
}
